package com.hl.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hl.domain.ConsultWait;
import com.hl.service.ConsultWaitService;
import com.hl.service.impl.ConsultWaitServiceImpl;
import com.hl.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/consultWait")
public class ConsultWaitController {
    @Autowired
    private ConsultWaitServiceImpl consultWaitService;
    @PostMapping
    public R add(@RequestBody ConsultWait consultWait){
        int i = consultWaitService.add(consultWait);
        return i > 0? R.success("新增成功"):R.fail("新增失败");
    }
    @DeleteMapping("/{id}")
    public R deleteById(@PathVariable("id") Integer id){
        int remove = consultWaitService.remove(id);
        return remove >0 ? R.success("删除成功") : R.fail("删除失败");
    }
    @DeleteMapping
    public R deleteBatch(Integer[] ids){
        int i = consultWaitService.removeBatch(ids);
        return i >0 ? R.success("批量删除成功") : R.fail("批量删除失败");
    }
    @GetMapping("/{id}")
    public R findById(@PathVariable("id") Integer id){
        ConsultWait byId = consultWaitService.findById(id);
        if (byId != null){
            return R.success(byId);
        }else {
            return R.fail("查询失败");
        }
    }
    @GetMapping("/all")
    public R findAll(){

        List<ConsultWait> list = consultWaitService.findAll();
        if (list != null){

            return R.success(list);
        }else {
            return R.fail("查询失败");
        }
    }
    @GetMapping
    public R findLike(String username,String name,int pageNum,int pageSize){
        PageHelper.startPage(pageNum,pageSize);

        List<ConsultWait> like = consultWaitService.findLike(username, name);

        PageInfo<ConsultWait>  pageInfo=new PageInfo<>(like);


        if (like != null){
            return R.success(pageInfo);
        }else {
            return R.fail("查询失败");
        }
    }
}





























